package adapter;

import java.util.List;

import javax.swing.JComponent;
import javax.swing.JList;

import protocal.DataPackage;
import protocal.DataPackage.MessageType;


public class UserListAdapter extends Adapter{
	
	private JList jList;
	private List<String> userList;
	

	public UserListAdapter(JComponent jList, List<String> userList) {
		this.jList = (JList) jList;
		this.userList = userList;
	}

	@Override
	public void adapter() {
		String[] names = new String[userList.size()];
		userList.toArray(names);
		jList.setListData(names);
	}

	@Override
	public void adapter(Object object) {
		DataPackage dataPackage = (DataPackage) object;
		if (dataPackage.getMessageType()==MessageType.LOGIN) {
			adapter();
		}
		if (dataPackage.getMessageType()==MessageType.LOGOUT) {
			adapter();
		}
	}

}
